<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>微商城</title>
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<meta name="format-detection" content="telephone=no">
<link href="__STATIC__/hotel/css/public.css" rel="stylesheet">
<link href="__STATIC__/hotel/css/style.css" rel="stylesheet">
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
</head>
<body>
<div id="mini_4">
	<!-- 顶部 -->
    <!-- <div class="header">
        <a href="javascript:history.go(-1)" class="lf">
            <img src="__STATIC__/hotel/images/left.png" alt="">
            <span>返回</span>
        </a>
        <span>微商城</span>
        <a href="javascript:void(0)" class="rt">
            <img src="__STATIC__/hotel/images/dot.png" alt="">
        </a>
    </div> -->
    <div class="product">
		<div class="product_img lf">
			<img src="__STATIC__/hotel/images/product_img.png" alt="">
		</div>
		<div class="product_detail">
			<p>{$info.name}</p>
			<p>
				<span>库存<i>{$info.rest}</i>件</span>
				<!-- <span>七寸</span> -->
			</p>
		</div>
	</div>
	<div class="room_price">
    	<span class="rt">总价<i>￥<i class="totalPrice">{$totalPrice}</i></i></span>
    	<div class="room_number">
    		<span >x</span>
    		<input class="print" type="text" readonly value="{$num}">
    		<!-- <span class="plus">+</span> -->
    	</div>
    </div>
    <div class="countDown">
    	倒计时：<span>10</span>时<span>50</span>分<span>20</span>秒
    </div>
    <div class="info">
        <ul>
            <li>联系人</li>
            <li>
                <input type="text" id='name' placeholder="请输入姓名">
            </li>
            <li id='sex'>
                <label for="sex-man" class="radio_label checked">
                    <input type="radio" value="1" checked="checked" id="sex-man" name="sex" />
                    先生
                </label>
                <label for="sex-female" class="radio_label">
                    <input type="radio" value="2" id="sex-female" name="sex" />
                    女士
                </label>
            </li>
        </ul>
        <ul>
            <li>手机号</li>
            <li>
                <input type="text" id='mobile' placeholder="请输入手机号">
            </li>
        </ul>
        <ul>
            <li>领取时间</li>
            <li>
                <input id='beizhu1' readonly value='<?php echo date('Y-m-d H:i:s',$info['starttime']);?>' type="text">
            </li>
        </ul>
    </div>
    <input type='hidden' id='foodid' value='{$info.id}'>
    <input type='hidden' id='kindid' value='{$info.kindid}'>
    <input type='hidden' id='price' value='{$totalPrice}'>
    <input type='hidden' id='openid' value='{$openid}'>
    <input type='hidden' id='norms' value='{$norms}'>
    <input type='hidden' id='lingqu_time' value='{$lingqu_time}'>
    <a  class="quickPay" onclick='checkInfo(this)'>
    	立即支付
    </a>
</div>
</body>
<script src="__STATIC__/hotel/js/jquery.js"></script>
<script type="text/javascript">
    $(function(){
        $('body').on('touchmove',function(event) {
            event.preventDefault();
        });

        // 单选按钮
        $("input[type='radio']").click(function(){
			$("input[type='radio'][name='"+$(this).attr('name')+"']").attr('checked',false).parent().removeClass("checked");
			$(this).attr('checked',true).parent().addClass("checked");
		});

        //订单单价
        var unitPrice=$('.totalPrice').html();
        //房间数量增加
        $('.plus').click(function(event) {
            var val=$(this).siblings('input').val();
            val++;
            $('.print').attr('value',val);
            $('.print').val(val);
            // 订单总额
            $('.totalPrice').html(parseFloat(unitPrice*val).toFixed(2));
            // 明细
            $('.number').html($('.print').val());
        });
        //房间数量减少
        $('.minus').click(function(event) {
            var val=$(this).siblings('input').val();
            val--;
            if(val<0){
                val=0;
            }
            $('.print').attr('value',val);
            $('.print').val(val);
            // 订单总额
            $('.totalPrice').html(parseFloat(unitPrice*val).toFixed(2));
            // 明细
            $('.number').html($('.print').val());
        });
        // input框内容改变
        $('.print').change(function(event) {
            var printCont=$(this).val();
            $('.print').attr('value',printCont);
            $('.print').val(printCont);
            // 订单总额
            $('.totalPrice').html(parseFloat(unitPrice*printCont).toFixed(2));
            // 明细
            $('.number').html($('.print').val());
        });
    });
</script>
</html>
<script type="text/javascript">
function checkInfo(obj){
    var name = $('#name').val();
    if(name == ''){
        alert('请输入姓名');return false;
    }
    var sex = $("input[type=radio]:checked").attr('value');
    
    var mobile = $('#mobile').val();
    if(mobile == ''){
        alert('请输入手机号码');return false;
    }
    if(!(/^1[3|4|5|7|8]\d{9}$/.test(mobile))){ 
            alert("手机号码格式有误，请重填");  
            return false; 
        }
    var beizhu = $('#beizhu').val();
    var norms = $('#norms').val();
    var foodid = $('#foodid').val();
    var kindid = $('#kindid').val();
    var lingqu_time = $('#lingqu_time').val();
    var num = $('.print').val();
    if(num <= 0){
        alert('请选择商品数量');return false;
    }
    var price = $('#price').val();
    var type = 'orderFood';
    $.ajax({
        url : "http://game.guangjixinxi.com/JinLingHotel/Mobile/Room/getMoney",
        type : 'GET',
        dataType : 'json',
        data: {type:type,name:name,sex:sex,mobile:mobile,beizhu:beizhu,foodid:foodid,kindid:kindid,price:price,num:num,lingqu_time:lingqu_time,norms:norms},
        success : function(res){
            // alert(res.val);return false;
            if(res.val == 1){
                alert(res.msg);return false;
            }
            if(res.val == 2){
                alert(res.msg);return false;
            }
            if(res.val == 4){
                alert(res.msg);return false;
            }
            if(res.val == 3){
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: '{$sign.appId}', // 必填，公众号的唯一标识
                    timestamp: {$sign.timestamp},
                    nonceStr:'{$sign.nonceStr}',
                    signature:'{$sign.signature}',
                    jsApiList:[
                        'checkJsApi',
                        'closeWindow',
                        'scanQRCode',
                        'chooseWXPay',
                    ]
                });
                 wx.ready(function(){
                       wx.chooseWXPay({
                           timestamp: res.timestamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                           nonceStr: res.paySign.nonceStr, // 支付签名随机串，不长于 32 位
                           package: res.paySign.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
                           signType: res.paySign.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                           paySign: res.paySign.paySign, // 支付签名
                           success: function (res) {
                               // 支付成功后的回调函数
                               var openid = $('#openid').val();
                               var num = $('.print').val();
                               $.ajax({
                                url:"http://game.guangjixinxi.com/JinLingHotel/Mobile/Room/changeFoodStatus",
                                data:{openid:openid,num:num},
                                dataType:'json',
                                type:'GET',
                                success:function(res){
                                    if(res.val == 1){
                                      // alert(res.msg);
                                      location.href="{:U('My/foodOrder')}";
                                    }else{
                                      alert('未知错误');return false;
                                    }
                                }
                               })
                           },
                           fail: function (res) {
                               alert('支付失败');return false;
                           },
                           });
                       // });
                         
                     });
            }else{
                alert('获取信息失败,请重新尝试');return false;
            }
        }
    })
}
</script>